<template>
  <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-width="120px"
      class="demo-ruleForm"
      :size="formSize"
      status-icon
  >
    <el-form-item label="头像">
      <UploadAvatar></UploadAvatar>
    </el-form-item>

    <el-form-item label="姓名" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="学号" prop="studentid">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="性别" prop="name">
      <div class="mb-2 flex items-center text-sm">
        <el-radio-group v-model="radio1" class="ml-4">
          <el-radio label="1" size="large" style="padding-left: 20px">男</el-radio>
          <el-radio label="2" size="large">女</el-radio>
        </el-radio-group>
      </div>
    </el-form-item>
    <el-form-item label="手机号" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
      <el-form-item label="所在学院" prop="region">
      <el-select v-model="ruleForm.region" placeholder="Activity zone">
        <el-option label="软件学院" value="软件学院" />
        <el-option label="信息学院" value="信息学院" />
      </el-select>
    </el-form-item>

    <el-form-item label="入学/毕业年月" required>
      <el-col :span="11">
        <el-form-item prop="date1">
          <el-date-picker
              v-model="ruleForm.date1"
              type="date"
              label="Pick a date"
              placeholder="Pick a date"
              style="width: 100%"
          />
        </el-form-item>
      </el-col>
      <el-col class="text-center" :span="2">
        <span class="text-gray-500">-</span>
      </el-col>
      <el-col :span="11">
        <el-form-item prop="date2">
          <el-date-picker
              v-model="ruleForm.date2"
              label="Pick a date"
              placeholder="Pick a date"
              style="width: 100%"
          />
        </el-form-item>
      </el-col>
    </el-form-item>

    <el-form-item label="修改密码" prop="name">
      <el-input
          v-model="input"
          type="password"
          placeholder="Please input password"
          show-password
      />
    </el-form-item>
    <el-form-item label="确认密码" prop="name">
      <el-input
          v-model="input1"
          type="password"
          placeholder="Please input password"
          show-password
      />
    </el-form-item>

    <el-form-item label="个人简介" prop="desc">
      <el-input v-model="ruleForm.desc" type="textarea" stype="margin-right: 40px"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormResf)"
      >提交</el-button
      >
      <el-button @click="resetForm(ruleFormRef)">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
import UploadAvatar from "@/components/UploadAvatar.vue";

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
const radio1 = ref('1')
const ruleForm = reactive({
  name: 'Hello',
  region: '',
  count: '',
  date1: '',
  date2: '',
  delivery: false,
  type: [],
  resource: '',
  desc: '',
})
const input = ref('')
const input1 = ref('')

const rules = reactive<FormRules>({
  name: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },
    { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
  region: [
    {
      required: true,
      message: 'Please select Activity zone',
      trigger: 'change',
    },
  ],
  count: [
    {
      required: true,
      message: 'Please select Activity count',
      trigger: 'change',
    },
  ],
  date1: [
    {
      type: 'date',
      required: true,
      message: 'Please pick a date',
      trigger: 'change',
    },
  ],
  date2: [
    {
      type: 'date',
      required: true,
      message: 'Please pick a time',
      trigger: 'change',
    },
  ],
  type: [
    {
      type: 'array',
      required: true,
      message: 'Please select at least one activity type',
      trigger: 'change',
    },
  ],
  resource: [
    {
      required: true,
      message: 'Please select activity resource',
      trigger: 'change',
    },
  ],
  desc: [
    { required: true, message: '个人简介', trigger: 'blur' },
  ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}

const options = Array.from({ length: 10000 }).map((_, idx) => ({
  value: `${idx + 1}`,
  label: `${idx + 1}`,
}))
</script>
<style>

.demo-ruleForm {
  padding-top: 10px;
  background-color: #f5f7fa;

}

.el-input {
  padding:0 40px 0 10px;
}

</style>